<?php
/* @var $this TrxReceiptController */
/* @var $model TrxReceipt */
/* @var $form TbActiveForm */
?>

<div class="form">

    <?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
	'id'=>'trx-receipt-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
)); ?>

    <p class="help-block">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>

            <div class="row">
	<div class="col-md-12">
						<div class="widget box">
							<div class="widget-header">
								<h4><i class="icon-reorder"></i>Payment To : </h4>
								<div class="controls">
				<div class="input-group">
				 <?php echo $form->textField($model,'client_name',array('class'=>'form-control input-width-medium','id'=>'client_name_1','maxlength'=>50,'style'=>'float:left','value'=>$data2['name'])); ?>
				 <?php echo $form->hiddenField($model, 'mst_client_id',array('class'=>'form-control input-width-small','id'=>'mst_client_id_1','readonly'=>true,'value'=>$data2['mst_client_id'])); ?>
					<a class="btn btn-default" href="#myModal" data-toggle="modal" style="float:left">+</a>
				</div>
								</div>
								<h4><i class="icon-reorder"></i>Bank </h4>
								<div class="controls">
				<div class="input-group">
				 <?php echo $form->dropDownList($model,'coa_credit_id',CHtml::listData(MstCoa::model()->findAll('id >= 11 and id <= 16 '), 'id','name'), array('class'=>'form-control','options' => array($data2['coa_credit_id']=>array('selected'=>true)))); ?>
				</div>
								</div>
								<h4><i class="icon-reorder"></i>Tgl. Transaksi </h4>
								<div class="controls">
				<div class="input-group">
				 <?php echo $form->textField($model,'tgl_transaksi', array('class'=>'form-control input-width-small','data-mask'=>"99-99-9999",'value'=>date('d-m-Y'))); ?>
				</div>
								</div>
								<div class="toolbar no-padding">
									<div class="btn-group">
										<span class="btn btn-xs widget-collapse"><i class="icon-angle-down"></i></span>
									</div>
								</div>
							</div>
							<div class="widget-content no-padding">
<table class="table table-hover table-striped table-bordered table-highlight-head">
	<thead>
		<tr>
			<th>No</th>
			<th>Jenis Trx</th>
			<th>DN/CN</th>
			<th>Account Code</th>
			<th>Jenis Mata Uang</th>
			<th>Nominal</th>
			<th>Keterangan</th>
		</tr>
	</thead>
	<tbody>
		<tr>
		
		<?php 
		for($i=0;$i<10;$i++){ 
		?>
			
			<td><?=$i+1?></td>
			<td>
			<?php echo $form->dropDownList($model, 'jns_trx', array(0 => "Pilih",1 => "Premi", 2 => "Non Premi", 3 => "Lain-lain"),array('class'=>'form-control input-width-small','id'=>'jns_trx_'.$i+1,'onChange'=>'enableNota(\''.$i.'\')')); ?>
			</td>
			<td>
				<div class="input-group">
				 <?php echo $form->textField($model,'nota_note',array('class'=>'form-control input-width-medium','id'=>'nota_note_'.$i,'maxlength'=>50,'style'=>'float:left','readonly'=>true,'onkeydown'=>'showData(event,\''.$i.'\')','name'=>'nota_note[]','value'=>$data[$i]['nota_note'])); ?>
				 <?php echo $form->hiddenField($model, 'no_nota_id',array('class'=>'form-control input-width-small','id'=>'no_nota_id_'.$i,'readonly'=>true)); ?>
				<input type="hidden" name="status_hg_nh[]" id="status_hg_nh_<?=$i?>" />
				</div>
			</td>
			
			<td><?php echo $form->dropDownList($model,'coa_debet_id',CHtml::listData(MstCoa::model()->findAll(), 'id','name'), array('class'=>'form-control','name'=>'coa_debet_id[]','prompt'=>'Select Account:','options' => array($data[$i]['coa_debet_id']=>array('selected'=>true)))); ?></td>
			
			<td><?php echo $form->dropDownList($model, 'jns_mata_uang', array(1 => "Rupiah", 2 => "$", 3 => "Euro"),array('class'=>'form-control input-width-small','id'=>'jns_mata_uang_'.$i,'name'=>'jns_mata_uang[]','name'=>'jns_mata_uang[]','options' => array($data2['jns_mata_uang']=>array('selected'=>true)))); ?></td>
			<td>
				<?php echo $form->textField($model,'nominal', array('class'=>'form-control input-width-small','name'=>'nominal[]','value'=>$data[$i]['nominal'])); ?>
			</td>
			<td>
				<?php echo $form->textArea($model,'keterangan', array('class'=>'form-control input-width-small','name'=>'keterangan[]')); ?>
			</td>
		</tr>
		<?php } ?>
		<tr>
			<td colspan="5" align="right"> <input type="button" value="Total" class="btn btn-primary" id="btn_total"></td>
			<td colspan="2"><label id="lbl_totalrp">Rp 0 </label> <br/><label id="lbl_totaldolar"> $ 0</label><br/><label id="lbl_totaleuro"> E 0</label></td>
		</tr>
	</tbody>
</table>


							</div>
						</div>
					</div>
	</div>

        <div class="form-actions">
        <?php echo TbHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array(
		    'color'=>TbHtml::BUTTON_COLOR_PRIMARY,
		    'size'=>TbHtml::BUTTON_SIZE_LARGE,
		)); ?>
    </div>

    <?php $this->endWidget(); ?>

</div><!-- form -->


<div id="myModal" class="modal fade in" style="display: none;" aria-hidden="false">
												<div class="modal-dialog" style="width:700px;">
													<div class="modal-content">
														<div class="modal-header">
															<button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
															<h4 class="modal-title">Pilih Nomor Nota</h4>
														</div>
														<div class="modal-body">
															
							<?php echo $this->renderPartial('//trxReceipt/_viewAllclient', array('model'=>$model3)); ?> 
														</div>
														<div class="modal-footer">
															<button data-dismiss="modal" class="btn btn-default" type="button">Close</button>
															<button id="btnTest" data-dismiss="modal" class="btn btn-primary" type="button">Pilih</button>
														</div>
													</div><!-- /.modal-content -->
												</div><!-- /.modal-dialog -->
</div>

	
<script type="text/javascript">
$( document ).ready(function() {
    var totali = 0.0;
	var total_dolari = 0.0;
	var total_euroi = 0.0;
	$('input[name="nominal[]"]').each(function(i,item) {
        var item = parseFloat($(this).val());
        if (isNaN(item)) item = 0;
		
		if( $('#jns_mata_uang_'+parseInt(i+1)).val() == "2"){
			total_dolari += item;
		}
		
		if( $('#jns_mata_uang_'+parseInt(i+1)).val() == "1"){
			totali += item;
		}
		if( $('#jns_mata_uang_'+parseInt(i+1)).val() == "3"){
			total_euroi += item;
		}
        
    });
	$('#lbl_totalrp').html("Rp. "+totali);
	$('#lbl_totaldolar').html("$ "+total_dolari);
	$('#lbl_totaleuro').html("E "+total_euroi);
});
$("#btn_total").click(function()
{
	var total = 0.0;
	var total_dolar = 0.0;
	var total_euro = 0.0;
	$('input[name="nominal[]"]').each(function(i,item) {
        var item = parseFloat($(this).val());
        if (isNaN(item)) item = 0;
		
		if( $('#jns_mata_uang_'+i).val() == "2"){
			total_dolar += item;
		}
		
		if( $('#jns_mata_uang_'+i).val() == "1"){
			total += item;
		}
		if( $('#jns_mata_uang_'+i).val() == "3"){
			total_euro += item;
		}
        
    });
	$('#lbl_totalrp').html("Rp. "+total);
	$('#lbl_totaldolar').html("$ "+total_dolar);
	$('#lbl_totaleuro').html("E "+total_euro);
});
function showData(e,id){
	/*var code = e.keyCode || e.which;
	  if (code == 9){
		//alert($("#nota_note_"+id).val());
			$.ajax({
			type:"POST",
            url:"<?php echo Yii::app()->createUrl('/TrxReceipt/showTagihan'); ?>",
			data:"id="+id+"&no_nota="+$("#nota_note_"+id).val(),
			dataType:"json",
            success:function(data){
				if(data.id==""){
					alert('No Nota Tidak Sesuai, Cek Kembali');
					$("#nota_note_"+id).focus();
				}else{
					if(data.code=='IDR'){
						var isi = data.code+' '+data.final_nominal;
					}else{
						var isi = data.code+' '+data.nominal+' <br/> Konversi : '+ 'IDR '+data.final_nominal;
					}
					$("#lbl_tagihan_"+id).html(isi);
					$("#no_nota_id_"+id).val(data.id);
					$("#status_hg_nh_"+id).val(data.jns_insurance);
				}
			}
		});
	  }//end if */
}
 
function enableNota(id){
	if($("#jns_trx_"+id).val() != '0'){
		$("#nota_note_"+id).attr("readonly",false);
		$("#nota_note_"+id).focus();
	}else{
		$("#nota_note_"+id).attr("readonly",false);
		$("#nota_note_"+id).focus();
	}
	
}

$("#btnTest").click(function()
{
	
	var nil = "";
    nil = $('input:radio[name=user]:checked').val();
   $("#mst_client_id_1").val(nil);
   $("#client_name_1").val($('input:radio[name=user]:checked').attr('nama_client'));
}); 


/*
function getId(id){
	$("#txt_get_id").val(id);
}

$(document).ready(function(){

$("#btnTest").click(function()
{
	
	var nil = "";
    nil = $('input:radio[name=user]:checked').val();
   $("#mst_client_id_1").val(nil);
   $("#client_name_1").val($('input:radio[name=user]:checked').attr('nama_client'));
}); 

$("#btnTest2").click(function()
{
	var id = $("#txt_get_id").val();
	var nil = "";
    nil = $('input:radio[name=get_nota]:checked').val();
   $("#no_nota_id_"+id).val(nil);
   $("#nota_note_"+id).val($('input:radio[name=get_nota]:checked').attr('nomor_nota'));
}); 

}); */
</script>